import { useNamespace } from "@/utils";
import { ExtractProps } from "@/utils/type";
import { PropType } from "vue";

export namespace variables {
  export const ns = useNamespace('Switch')
  export type DotProps = Partial<{
    /**
     * 设置此项会忽略 text
     */
    icon: string
    /**
     * switch 的文字描述
     */
    text: string
    /**
     * switch 的值
     */
    value: boolean | string | number
    /**
     * 圆点上的 icon 图标
     */
    actionIcon: string
  }>
}

export namespace SwitchNS {
  export const name = variables.ns.name
  export const props = {
    modelValue: [Boolean, String, Number],
    disabled: Boolean,
    loading: Boolean,
    /**
     * 选中时的配置项
     */
    active: Object as PropType<variables.DotProps>,
    /**
     * 未选中时的配置项
     */
    inactive: Object as PropType<variables.DotProps>,
    /**
     * switch 切换前会触发此函数，如果是 reject 则停止切换
     */
    beforeChange: Function as PropType<() => Promise<any>>,
    /**
     * 是否将文字或图标放置在 switch 之内
     */
    inlinePrompt: Boolean,
  }
  export const emits = {
    change: (val: variables.DotProps['value']) => true,
    'update:modelValue': (val: variables.DotProps['value']) => true
  }
  export type Props = ExtractProps.Types<typeof props> & PartialEmits<typeof emits>
  export const Component = <{
    new(): {
      $props: Props
    }
  }>{}
}